﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CSmcCs;

namespace BaseMove
{
	/// <summary>
	/// Summary description for BaseMove.
	/// </summary>
	public class BaseMove : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtDeviceName;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.ComboBox cboTargetAxis;
		private System.Windows.Forms.TextBox txtResolution;
		private System.Windows.Forms.TextBox txtStartSpeed;
		private System.Windows.Forms.TextBox txtTargetSpeed;
		private System.Windows.Forms.TextBox txtAccelTime;
		private System.Windows.Forms.TextBox txtDecelTime;
		private System.Windows.Forms.TextBox txtSSpeed;
		private System.Windows.Forms.TextBox txtDistance;
		private System.Windows.Forms.RadioButton rdoPtp;
		private System.Windows.Forms.RadioButton rdoJog;
		private System.Windows.Forms.RadioButton rdoOrg;
		private System.Windows.Forms.Button btnComCw;
		private System.Windows.Forms.Button btnComCcw;
		private System.Windows.Forms.Button btnComStop;
		private System.Windows.Forms.Button btnComSdStop;
		private System.Windows.Forms.ComboBox cboCoordinate;
		private System.Windows.Forms.ComboBox cboChange;
		private System.Windows.Forms.Button btnComChange;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Label lblComment;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		int			dwRet;
		short		MotionType;
		double		dblResolveSpeed;
		double		dblStartSpeed;
		double		dblTargetSpeed;
		double		dblAccelTime;
		double		dblDecelTime;
		double		dblSSpeed;
		int			lDistance;
		string		ErrorString;
		short		StartDir;
		bool		bRet;
		short		Id=-1;
		short		AxisNo;
		short		bCoordinate;
		short		Change;

		CSmc		Smc	= new CSmc();

		public BaseMove()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.txtDeviceName = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.cboTargetAxis = new System.Windows.Forms.ComboBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label16 = new System.Windows.Forms.Label();
			this.label15 = new System.Windows.Forms.Label();
			this.label14 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.txtDistance = new System.Windows.Forms.TextBox();
			this.txtSSpeed = new System.Windows.Forms.TextBox();
			this.txtDecelTime = new System.Windows.Forms.TextBox();
			this.txtAccelTime = new System.Windows.Forms.TextBox();
			this.txtTargetSpeed = new System.Windows.Forms.TextBox();
			this.txtStartSpeed = new System.Windows.Forms.TextBox();
			this.txtResolution = new System.Windows.Forms.TextBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.cboCoordinate = new System.Windows.Forms.ComboBox();
			this.label17 = new System.Windows.Forms.Label();
			this.btnComSdStop = new System.Windows.Forms.Button();
			this.btnComStop = new System.Windows.Forms.Button();
			this.btnComCcw = new System.Windows.Forms.Button();
			this.btnComCw = new System.Windows.Forms.Button();
			this.rdoOrg = new System.Windows.Forms.RadioButton();
			this.rdoJog = new System.Windows.Forms.RadioButton();
			this.rdoPtp = new System.Windows.Forms.RadioButton();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.btnComChange = new System.Windows.Forms.Button();
			this.cboChange = new System.Windows.Forms.ComboBox();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.lblComment = new System.Windows.Forms.Label();
//@@@			this.btnHelp = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox4.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(15, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(79, 14);
			this.label1.TabIndex = 0;
			this.label1.Text = "Device Name";
			// 
			// txtDeviceName
			// 
			this.txtDeviceName.Location = new System.Drawing.Point(120, 13);
			this.txtDeviceName.Name = "txtDeviceName";
			this.txtDeviceName.Size = new System.Drawing.Size(120, 21);
			this.txtDeviceName.TabIndex = 2;
			this.txtDeviceName.Text = "";
			this.txtDeviceName.TextChanged += new System.EventHandler(this.txtDeviceName_TextChanged);
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(328, 16);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(44, 14);
			this.label2.TabIndex = 2;
			this.label2.Text = "AxisNo";
			// 
			// cboTargetAxis
			// 
			this.cboTargetAxis.Location = new System.Drawing.Point(392, 12);
			this.cboTargetAxis.Name = "cboTargetAxis";
			this.cboTargetAxis.Size = new System.Drawing.Size(80, 23);
			this.cboTargetAxis.Sorted = true;
			this.cboTargetAxis.TabIndex = 3;
			this.cboTargetAxis.SelectedIndexChanged += new System.EventHandler(this.cboTargetAxis_SelectedIndexChanged);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.label16,
																					this.label15,
																					this.label14,
																					this.label13,
																					this.label12,
																					this.label11,
																					this.label10,
																					this.label9,
																					this.label8,
																					this.label7,
																					this.label6,
																					this.label5,
																					this.label4,
																					this.label3,
																					this.txtDistance,
																					this.txtSSpeed,
																					this.txtDecelTime,
																					this.txtAccelTime,
																					this.txtTargetSpeed,
																					this.txtStartSpeed,
																					this.txtResolution});
			this.groupBox1.Location = new System.Drawing.Point(8, 48);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(304, 280);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "PARAMETERS";
			// 
			// label16
			// 
			this.label16.AutoSize = true;
			this.label16.Location = new System.Drawing.Point(248, 250);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(41, 14);
			this.label16.TabIndex = 20;
			this.label16.Text = "[pulse]";
			// 
			// label15
			// 
			this.label15.AutoSize = true;
			this.label15.Location = new System.Drawing.Point(248, 213);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(31, 14);
			this.label15.TabIndex = 19;
			this.label15.Text = "[pps]";
			// 
			// label14
			// 
			this.label14.AutoSize = true;
			this.label14.Location = new System.Drawing.Point(248, 176);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(28, 14);
			this.label14.TabIndex = 18;
			this.label14.Text = "[ms]";
			// 
			// label13
			// 
			this.label13.AutoSize = true;
			this.label13.Location = new System.Drawing.Point(248, 139);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(28, 14);
			this.label13.TabIndex = 17;
			this.label13.Text = "[ms]";
			// 
			// label12
			// 
			this.label12.AutoSize = true;
			this.label12.Location = new System.Drawing.Point(248, 96);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(31, 14);
			this.label12.TabIndex = 16;
			this.label12.Text = "[pps]";
			// 
			// label11
			// 
			this.label11.AutoSize = true;
			this.label11.Location = new System.Drawing.Point(248, 65);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(31, 14);
			this.label11.TabIndex = 15;
			this.label11.Text = "[pps]";
			// 
			// label10
			// 
			this.label10.AutoSize = true;
			this.label10.Location = new System.Drawing.Point(248, 28);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(31, 14);
			this.label10.TabIndex = 14;
			this.label10.Text = "[pps]";
			// 
			// label9
			// 
			this.label9.AutoSize = true;
			this.label9.Location = new System.Drawing.Point(9, 250);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(53, 14);
			this.label9.TabIndex = 13;
			this.label9.Text = "Distance";
			// 
			// label8
			// 
			this.label8.AutoSize = true;
			this.label8.Location = new System.Drawing.Point(9, 213);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(52, 14);
			this.label8.TabIndex = 12;
			this.label8.Text = "S Speed";
			// 
			// label7
			// 
			this.label7.AutoSize = true;
			this.label7.Location = new System.Drawing.Point(9, 176);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(67, 14);
			this.label7.TabIndex = 11;
			this.label7.Text = "Decel Time";
			// 
			// label6
			// 
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(9, 139);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(66, 14);
			this.label6.TabIndex = 10;
			this.label6.Text = "Accel Time";
			// 
			// label5
			// 
			this.label5.AutoSize = true;
			this.label5.Location = new System.Drawing.Point(9, 96);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(79, 14);
			this.label5.TabIndex = 9;
			this.label5.Text = "Target Speed";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Location = new System.Drawing.Point(9, 65);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(70, 14);
			this.label4.TabIndex = 8;
			this.label4.Text = "Start Speed";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(9, 28);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(63, 14);
			this.label3.TabIndex = 7;
			this.label3.Text = "Resolution";
			// 
			// txtDistance
			// 
			this.txtDistance.Location = new System.Drawing.Point(112, 247);
			this.txtDistance.Name = "txtDistance";
			this.txtDistance.Size = new System.Drawing.Size(120, 21);
			this.txtDistance.TabIndex = 6;
			this.txtDistance.Text = "";
			// 
			// txtSSpeed
			// 
			this.txtSSpeed.Location = new System.Drawing.Point(112, 210);
			this.txtSSpeed.Name = "txtSSpeed";
			this.txtSSpeed.Size = new System.Drawing.Size(120, 21);
			this.txtSSpeed.TabIndex = 5;
			this.txtSSpeed.Text = "";
			// 
			// txtDecelTime
			// 
			this.txtDecelTime.Location = new System.Drawing.Point(112, 173);
			this.txtDecelTime.Name = "txtDecelTime";
			this.txtDecelTime.Size = new System.Drawing.Size(120, 21);
			this.txtDecelTime.TabIndex = 4;
			this.txtDecelTime.Text = "";
			// 
			// txtAccelTime
			// 
			this.txtAccelTime.Location = new System.Drawing.Point(112, 136);
			this.txtAccelTime.Name = "txtAccelTime";
			this.txtAccelTime.Size = new System.Drawing.Size(120, 21);
			this.txtAccelTime.TabIndex = 3;
			this.txtAccelTime.Text = "";
			// 
			// txtTargetSpeed
			// 
			this.txtTargetSpeed.Location = new System.Drawing.Point(112, 93);
			this.txtTargetSpeed.Name = "txtTargetSpeed";
			this.txtTargetSpeed.Size = new System.Drawing.Size(120, 21);
			this.txtTargetSpeed.TabIndex = 2;
			this.txtTargetSpeed.Text = "";
			// 
			// txtStartSpeed
			// 
			this.txtStartSpeed.Location = new System.Drawing.Point(112, 62);
			this.txtStartSpeed.Name = "txtStartSpeed";
			this.txtStartSpeed.Size = new System.Drawing.Size(120, 21);
			this.txtStartSpeed.TabIndex = 1;
			this.txtStartSpeed.Text = "";
			// 
			// txtResolution
			// 
			this.txtResolution.Location = new System.Drawing.Point(112, 25);
			this.txtResolution.Name = "txtResolution";
			this.txtResolution.Size = new System.Drawing.Size(120, 21);
			this.txtResolution.TabIndex = 0;
			this.txtResolution.Text = "";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboCoordinate,
																					this.label17,
																					this.btnComSdStop,
																					this.btnComStop,
																					this.btnComCcw,
																					this.btnComCw,
																					this.rdoOrg,
																					this.rdoJog,
																					this.rdoPtp});
			this.groupBox2.Location = new System.Drawing.Point(320, 48);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(245, 192);
			this.groupBox2.TabIndex = 5;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "MOTION";
			// 
			// cboCoordinate
			// 
			this.cboCoordinate.Location = new System.Drawing.Point(96, 156);
			this.cboCoordinate.Name = "cboCoordinate";
			this.cboCoordinate.Size = new System.Drawing.Size(104, 23);
			this.cboCoordinate.TabIndex = 8;
			this.cboCoordinate.SelectedIndexChanged += new System.EventHandler(this.cboCoordinate_SelectedIndexChanged);
			// 
			// label17
			// 
			this.label17.AutoSize = true;
			this.label17.Location = new System.Drawing.Point(8, 160);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(68, 14);
			this.label17.TabIndex = 7;
			this.label17.Text = "INC or ABS";
			// 
			// btnComSdStop
			// 
			this.btnComSdStop.Location = new System.Drawing.Point(96, 108);
			this.btnComSdStop.Name = "btnComSdStop";
			this.btnComSdStop.Size = new System.Drawing.Size(120, 32);
			this.btnComSdStop.TabIndex = 6;
			this.btnComSdStop.Text = "SD Stop";
			this.btnComSdStop.Click += new System.EventHandler(this.btnComSdStop_Click);
			// 
			// btnComStop
			// 
			this.btnComStop.Location = new System.Drawing.Point(96, 66);
			this.btnComStop.Name = "btnComStop";
			this.btnComStop.Size = new System.Drawing.Size(120, 32);
			this.btnComStop.TabIndex = 5;
			this.btnComStop.Text = "STOP";
			this.btnComStop.Click += new System.EventHandler(this.btnComStop_Click);
			// 
			// btnComCcw
			// 
			this.btnComCcw.Location = new System.Drawing.Point(160, 24);
			this.btnComCcw.Name = "btnComCcw";
			this.btnComCcw.Size = new System.Drawing.Size(56, 32);
			this.btnComCcw.TabIndex = 4;
			this.btnComCcw.Text = "CCW";
			this.btnComCcw.Click += new System.EventHandler(this.btnComCcw_Click);
			// 
			// btnComCw
			// 
			this.btnComCw.Location = new System.Drawing.Point(96, 24);
			this.btnComCw.Name = "btnComCw";
			this.btnComCw.Size = new System.Drawing.Size(56, 32);
			this.btnComCw.TabIndex = 3;
			this.btnComCw.Text = "CW";
			this.btnComCw.Click += new System.EventHandler(this.btnComCw_Click);
			// 
			// rdoOrg
			// 
			this.rdoOrg.Location = new System.Drawing.Point(8, 87);
			this.rdoOrg.Name = "rdoOrg";
			this.rdoOrg.Size = new System.Drawing.Size(64, 16);
			this.rdoOrg.TabIndex = 2;
			this.rdoOrg.Text = "ORG";
			this.rdoOrg.CheckedChanged += new System.EventHandler(this.rdoOrg_CheckedChanged);
			// 
			// rdoJog
			// 
			this.rdoJog.Location = new System.Drawing.Point(8, 58);
			this.rdoJog.Name = "rdoJog";
			this.rdoJog.Size = new System.Drawing.Size(64, 16);
			this.rdoJog.TabIndex = 1;
			this.rdoJog.Text = "JOG";
			this.rdoJog.CheckedChanged += new System.EventHandler(this.rdoJog_CheckedChanged);
			// 
			// rdoPtp
			// 
			this.rdoPtp.Location = new System.Drawing.Point(8, 29);
			this.rdoPtp.Name = "rdoPtp";
			this.rdoPtp.Size = new System.Drawing.Size(64, 16);
			this.rdoPtp.TabIndex = 0;
			this.rdoPtp.Text = "PTP";
			this.rdoPtp.CheckedChanged += new System.EventHandler(this.rdoPtp_CheckedChanged);
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.btnComChange,
																					this.cboChange});
			this.groupBox3.Location = new System.Drawing.Point(320, 256);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(245, 72);
			this.groupBox3.TabIndex = 6;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "MOTION CHANGE";
			// 
			// btnComChange
			// 
			this.btnComChange.Location = new System.Drawing.Point(168, 28);
			this.btnComChange.Name = "btnComChange";
			this.btnComChange.Size = new System.Drawing.Size(64, 32);
			this.btnComChange.TabIndex = 10;
			this.btnComChange.Text = "Change";
			this.btnComChange.Click += new System.EventHandler(this.btnComChange_Click);
			// 
			// cboChange
			// 
			this.cboChange.Location = new System.Drawing.Point(8, 33);
			this.cboChange.Name = "cboChange";
			this.cboChange.Size = new System.Drawing.Size(152, 23);
			this.cboChange.TabIndex = 9;
			this.cboChange.SelectedIndexChanged += new System.EventHandler(this.cboChange_SelectedIndexChanged);
			// 
			// groupBox4
			// 
			this.groupBox4.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lblComment});
			this.groupBox4.Location = new System.Drawing.Point(8, 336);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.Size = new System.Drawing.Size(448, 144);
			this.groupBox4.TabIndex = 7;
			this.groupBox4.TabStop = false;
			this.groupBox4.Text = "COMMENT";
			// 
			// lblComment
			// 
			this.lblComment.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblComment.Location = new System.Drawing.Point(8, 24);
			this.lblComment.Name = "lblComment";
			this.lblComment.Size = new System.Drawing.Size(432, 112);
			this.lblComment.TabIndex = 0;
			this.lblComment.Text = "label18";
//@@@
//			// 
//			// btnHelp
//			// 
//			this.btnHelp.Location = new System.Drawing.Point(469, 376);
//			this.btnHelp.Name = "btnHelp";
//			this.btnHelp.Size = new System.Drawing.Size(96, 32);
//			this.btnHelp.TabIndex = 0;
//			this.btnHelp.Text = "HELP";
//			this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(469, 424);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(96, 32);
			this.btnExit.TabIndex = 1;
			this.btnExit.Text = "EXIT";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// BaseMove
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(574, 486);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnExit,
//@@@																		  this.btnHelp,
																		  this.groupBox4,
																		  this.groupBox3,
																		  this.groupBox2,
																		  this.groupBox1,
																		  this.cboTargetAxis,
																		  this.label2,
																		  this.txtDeviceName,
																		  this.label1});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "BaseMove";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "BaseMove";
			this.Load += new System.EventHandler(this.BaseMove_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new BaseMove());
		}

		private void BaseMove_Load(object sender, System.EventArgs e)
		{
			AxisNo = 1;

			// AxisNo ComboBox
			for( int i=0; i<8; i++ )
			{
				cboTargetAxis.Items.Add(i+1);
			}

			// ComboBox Initialise
			cboTargetAxis.SelectedIndex = AxisNo - 1;

			// Coordinate ComboBox
			cboCoordinate.Items.Add("ABS");
			cboCoordinate.Items.Add("INC");
			cboCoordinate.SelectedIndex = (int)CSmcConst.CSMC_INC;

			// Coordinate ComboBox
			cboChange.Items.Add("At once FL");
			cboChange.Items.Add("At once FH");
			cboChange.Items.Add("Decel FL");
			cboChange.Items.Add("Accel FH");
			cboChange.Items.Add("Motion Change");
			cboChange.Items.Add("Position Change1");
			cboChange.Items.Add("Position Change2");
			cboChange.SelectedIndex = 4;

			// Initialize
			dblResolveSpeed = 0;
			dblStartSpeed = 0;
			dblTargetSpeed = 0;
			dblAccelTime = 0;
			dblDecelTime = 0;
			dblSSpeed = 0;
			lDistance = 0;

			rdoPtp.Checked = true;

			bCoordinate = (short)CSmcConst.CSMC_INC;
			MotionType = (short)CSmcConst.CSMC_PTP;	

			//------------
			// Initialize
			//------------
			txtDeviceName.Text = "SMC000";
		}

		private void DispComment(string func, string msg) 
		{
			lblComment.Text = string.Format("{0}: {1}", func, msg);
		}

		private bool SetMoveParam()
		{
			string	wStr="OK";
			//----------------------------------
			// Set Resolution to Driver
			//----------------------------------
			wStr = txtResolution.Text;			
			try
			{
				dblResolveSpeed = double.Parse(wStr);
			}
			catch (FormatException)
			{
				dblResolveSpeed = 0;;
			}
			dwRet = Smc.WSetResolveSpeed(Id, AxisNo, dblResolveSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetResolveSpeed", ErrorString);
				return false;
			}

			//----------------------------------
			// Set StartSpeed to Driver
			//----------------------------------
			wStr = txtStartSpeed.Text;
			try
			{
				dblStartSpeed = double.Parse(wStr);
			}
			catch (FormatException)
			{
				dblStartSpeed = 0;
			}
			dwRet = Smc.WSetStartSpeed(Id, AxisNo, dblStartSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetStartSpeed", ErrorString);
				return false;
			}
			//----------------------------------
			// Set TargetSpeed to Driver
			//----------------------------------
			wStr = txtTargetSpeed.Text;
			try
			{
				dblTargetSpeed = double.Parse(wStr);
			}
			catch (FormatException)
			{
				dblTargetSpeed = 0;
			}
			dwRet = Smc.WSetTargetSpeed(Id, AxisNo, dblTargetSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetTargetSpeed", ErrorString);
				return false;
			}
			//----------------------------------
			// Set AccelTime to Driver
			//----------------------------------
			wStr = txtAccelTime.Text;
			try
			{
				dblAccelTime = double.Parse(wStr);
			}
			catch (FormatException)
			{
				dblAccelTime = 0;
			}
			dwRet = Smc.WSetAccelTime(Id, AxisNo, dblAccelTime);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetAccelTime", ErrorString);
				return false;
			}
			//----------------------------------
			// Set DecelTime to Driver
			//----------------------------------
			wStr = txtDecelTime.Text;
			try
			{
				dblDecelTime = double.Parse(wStr);
			}
			catch (FormatException)
			{
				dblDecelTime = 0;
			}
			dwRet = Smc.WSetDecelTime(Id, AxisNo, dblDecelTime);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetDecelTime", ErrorString);
				return false;
			}
			//-----------------------------
			// Set SSpeed to Driver
			//-----------------------------
			wStr = txtSSpeed.Text;
			try
			{
				dblSSpeed = double.Parse(wStr);
			}
			catch (FormatException)
			{
				dblSSpeed = 0;
			}
			dwRet = Smc.WSetSSpeed(Id, AxisNo, dblSSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetSSpeed", ErrorString);
				return false;
			}
			//-------------------------
			// Set Distance to Driver
			//-------------------------
			wStr = txtDistance.Text;
			try
			{
				lDistance = int.Parse(wStr);
			}
			catch (FormatException)
			{
				lDistance = 0;
			}
			if( MotionType == (short)CSmcConst.CSMC_PTP  && bCoordinate == (short)CSmcConst.CSMC_INC )
			{
				lDistance = Math.Abs(lDistance);
				if( StartDir == (short)CSmcConst.CSMC_CCW )
				{
					lDistance = -1*(lDistance);
				}
			}
			dwRet = Smc.WSetStopPosition(Id, AxisNo, bCoordinate, lDistance);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetStopPosition", ErrorString);
				return false;
			}
			lblComment.Text = wStr;
			return true;
		}

		private bool GetMoveParam()
		{
			string	wStr="OK";
			//----------------------------------
			// Set default value of Resolution
			//----------------------------------
			dwRet = Smc.WGetResolveSpeed(Id, AxisNo, out dblResolveSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetResolveSpeed", ErrorString);
				return false;
			}
			if( dblResolveSpeed == (int)dblResolveSpeed )
				wStr = string.Format("{0:d}", (int)dblResolveSpeed);
			else
				wStr = string.Format("{0:f}", dblResolveSpeed);
			txtResolution.Text = wStr;
			//----------------------------------
			// Set default value of StartSpeed
			//----------------------------------
			dwRet = Smc.WGetStartSpeed(Id, AxisNo, out dblStartSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetStartSpeed", ErrorString);
				return false;
			}
			if( dblStartSpeed == (int)dblStartSpeed )
				wStr = string.Format("{0:d}", (int)dblStartSpeed);
			else
				wStr = string.Format("{0:f}", dblStartSpeed);
			txtStartSpeed.Text = wStr;
			//----------------------------------
			// Set default value of TargetSpeed
			//----------------------------------
			dwRet = Smc.WGetTargetSpeed(Id, AxisNo, out dblTargetSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetTargetSpeed", ErrorString);
				return false;
			}
			if( dblTargetSpeed == (int)dblTargetSpeed )
				wStr = string.Format("{0:d}", (int)dblTargetSpeed);
			else
				wStr = string.Format("{0:f}", dblTargetSpeed);
			txtTargetSpeed.Text = wStr;
			//----------------------------------
			// Set default value of AccelTime
			//----------------------------------
			dwRet = Smc.WGetAccelTime(Id, AxisNo, out dblAccelTime);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetAccelTime", ErrorString);
				return false;
			}
			if( dblAccelTime == (int)dblAccelTime )
				wStr = string.Format("{0:d}", (int)dblAccelTime);
			else
				wStr = string.Format("{0:f}", dblAccelTime);
			txtAccelTime.Text = wStr;
			//----------------------------------
			// Set default value of DecelTime
			//----------------------------------
			dwRet = Smc.WGetDecelTime(Id, AxisNo, out dblDecelTime);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetDecelTime", ErrorString);
				return false;
			}
			if( dblDecelTime == (int)dblDecelTime )
				wStr = string.Format("{0:d}", (int)dblDecelTime);
			else
				wStr = string.Format("{0:f}", dblDecelTime);
			txtDecelTime.Text = wStr;
			//-----------------------------
			// Set default value of SSpeed
			//-----------------------------
			dwRet = Smc.WGetSSpeed(Id, AxisNo, out dblSSpeed);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetSSpeed", ErrorString);
				return false;
			}
			if( dblSSpeed == (int)dblSSpeed )
				wStr = string.Format("{0:d}", (int)dblSSpeed);
			else
				wStr = string.Format("{0:f}", dblSSpeed);
			txtSSpeed.Text = wStr;
			//----------------------------------
			// Set default value of lDistance
			//----------------------------------
			dwRet = Smc.WGetStopPosition(Id, AxisNo, bCoordinate, out lDistance);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetStopPosition", ErrorString);
				return false;
			}
			wStr = string.Format("{0:d}", lDistance);
			txtDistance.Text = wStr;

			return true;
		}

		private void btnComCcw_Click(object sender, System.EventArgs e)
		{
			string	wStr="OK";
			StartDir = (short)CSmcConst.CSMC_CCW;
			//----------------------------------
			// Set parameters to Driver
			//----------------------------------
			bRet = SetMoveParam();
			if( bRet == false ) return ;
			//---------------
			// Ready motion
			//---------------
			dwRet = Smc.WSetReady(Id, AxisNo, MotionType, StartDir);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetReady", ErrorString);
				return;
			}
			//---------------
			// Start Motion
			//---------------
			dwRet = Smc.WMotionStart(Id, AxisNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWMotionStart", ErrorString);
				return;
			}
			lblComment.Text = wStr;
			//-------------------------------------
			// Get setting parameters from Driver
			//-------------------------------------
			bRet = GetMoveParam();
		}

		private void btnComCw_Click(object sender, System.EventArgs e)
		{
			string	wStr="OK";
			StartDir = (short)CSmcConst.CSMC_CW;
			//----------------------------------
			// Set parameters to Driver
			//----------------------------------
			bRet = SetMoveParam();
			if( bRet == false ) return;
			//---------------
			// Ready motion
			//---------------
			dwRet = Smc.WSetReady(Id, AxisNo, MotionType, StartDir);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetReady", ErrorString);
				return;
			}
			//---------------
			// Start Motion
			//---------------
			dwRet = Smc.WMotionStart(Id, AxisNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWMotionStart", ErrorString);
				return;
			}
			lblComment.Text = wStr;
			//-------------------------------------
			// Get setting parameters from Driver
			//-------------------------------------
			bRet = GetMoveParam();
			if( bRet == false ) return;
		}

		private void btnComStop_Click(object sender, System.EventArgs e)
		{
			string	wStr="OK";
			dwRet = Smc.WMotionStop(Id, AxisNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWMotionStop", ErrorString);
				return;
			}
			lblComment.Text = wStr;
		}

		private void btnComSdStop_Click(object sender, System.EventArgs e)
		{
			string	wStr="OK";
			dwRet = Smc.WMotionDecStop(Id, AxisNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWMotionDecStop", ErrorString);
				return;
			}
			lblComment.Text = wStr;
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			Smc.WExit(Id);

			this.Close();
		}

		private void rdoPtp_CheckedChanged(object sender, System.EventArgs e)
		{
			MotionType = (short)CSmcConst.CSMC_PTP;
		}

		private void rdoJog_CheckedChanged(object sender, System.EventArgs e)
		{
			MotionType = (short)CSmcConst.CSMC_JOG;
		}

		private void rdoOrg_CheckedChanged(object sender, System.EventArgs e)
		{
			MotionType = (short)CSmcConst.CSMC_ORG;
		}

		private void cboCoordinate_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if( cboCoordinate.SelectedIndex == 0 )
				bCoordinate = (short)CSmcConst.CSMC_ABS;
			else
				bCoordinate = (short)CSmcConst.CSMC_INC;
		}

		private void txtDeviceName_TextChanged(object sender, System.EventArgs e)
		{
			string	wStr="OK";

			if( Id != -1 )
			{
				Smc.WExit(Id);
			}
			wStr = txtDeviceName.Text;
			dwRet = Smc.WInit(wStr, out Id);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWInit", ErrorString);
				Id = -1;
				return ;
			}

			// ------------------------
			// Set lDistance to 1000
			// ------------------------
			lDistance = 1000;
			dwRet = Smc.WSetStopPosition(Id, AxisNo, bCoordinate, lDistance);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetStopPosition", ErrorString);
				return ;
			}
			wStr="OK";
			lblComment.Text = wStr;
			//---------------------------
			// Get parameters of Driver
			//---------------------------
			bRet = GetMoveParam();
			if( bRet == false )return;
		}

		private void cboTargetAxis_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			AxisNo=(short)(cboTargetAxis.SelectedIndex+1);	
			// InitParam Check
			short InitParam;
			dwRet = Smc.WGetInitParam(Id , AxisNo , out InitParam);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWGetInitParam", ErrorString);
				return ;
			}
			if( InitParam == 0 )
			{ // SmcWSetInitParam
				dwRet = Smc.WSetInitParam(Id , AxisNo);
				if( dwRet != 0 )
				{
					Smc.WGetErrorString(dwRet, out ErrorString);
					DispComment("SmcWSetInitParam", ErrorString);
					return ;
				}
			}
			// ------------------------
			// Set lDistance to 1000
			// ------------------------
			lDistance = 1000;
			dwRet = Smc.WSetStopPosition(Id, AxisNo, bCoordinate, lDistance);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetStopPosition", ErrorString);
				return ;
			}
			//---------------------------
			// Get parameters of Driver
			//---------------------------
			bRet = GetMoveParam();
			if( bRet == false )return;
		}

		private void cboChange_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Change=(short)cboChange.SelectedIndex;
		}

		private void btnComChange_Click(object sender, System.EventArgs e)
		{
			string	wStr;
			if( Change == 4 )
			{
				//----------------------------------
				// Set TargetSpeed to Driver
				//----------------------------------
				wStr = txtTargetSpeed.Text;
				try
				{
					dblTargetSpeed = double.Parse(wStr);
				}
				catch (FormatException)
				{
					dblTargetSpeed = 0;
				}
				dwRet = Smc.WSetTargetSpeed(Id, AxisNo, dblTargetSpeed);
				if( dwRet != 0 )
				{
					Smc.WGetErrorString(dwRet, out ErrorString);
					DispComment("SmcWSetTargetSpeed", ErrorString);
					return ;
				}
				//----------------------------------
				// Set AccelTime to Driver
				//----------------------------------
				wStr = txtAccelTime.Text;
				try
				{
					dblAccelTime = double.Parse(wStr);
				}
				catch (FormatException)
				{
					dblAccelTime = 0;
				}
				dwRet = Smc.WSetAccelTime(Id, AxisNo, dblAccelTime);
				if( dwRet != 0 )
				{
					Smc.WGetErrorString(dwRet, out ErrorString);
					DispComment("SmcWSetAccelTime", ErrorString);
					return ;
				}
				//----------------------------------
				// Set DecelTime to Driver
				//----------------------------------
				wStr = txtDecelTime.Text;
				try
				{
					dblDecelTime = double.Parse(wStr);
				}
				catch (FormatException)
				{
					dblDecelTime = 0;
				}
				dwRet = Smc.WSetDecelTime(Id, AxisNo, dblDecelTime);
				if( dwRet != 0 )
				{
					Smc.WGetErrorString(dwRet, out ErrorString);
					DispComment("SmcWSetDecelTime", ErrorString);
					return ;
				}
			}

			if( Change == 5 || Change == 6 )
			{
				//-------------------------
				// Set Distance to Driver
				//-------------------------
				wStr = txtDistance.Text;
				try
				{
					lDistance = int.Parse(wStr);
				}
				catch (FormatException)
				{
					lDistance = 0;
				}
				if( MotionType == (short)CSmcConst.CSMC_PTP  && bCoordinate == (short)CSmcConst.CSMC_INC )
				{
					lDistance = Math.Abs(lDistance);
					if( StartDir == (short)CSmcConst.CSMC_CCW )
					{
						lDistance = -1*(lDistance);
					}
				}
				dwRet = Smc.WSetStopPosition(Id, AxisNo, bCoordinate, lDistance);
				if( dwRet != 0 )
				{
					Smc.WGetErrorString(dwRet, out ErrorString);
					DispComment("SmcWSetStopPosition", ErrorString);
					return ;
				}
			}

			//--------------------
			// Set Change Motion
			//--------------------
			dwRet = Smc.WSetMotionChangeReady(Id, AxisNo, Change);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWSetMotionChangeReady", ErrorString);
				return ;
			}
    
			//----------------
			// Change Motion
			//----------------
			dwRet = Smc.WMotionChange(Id, AxisNo);
			if( dwRet != 0 )
			{
				Smc.WGetErrorString(dwRet, out ErrorString);
				DispComment("SmcWMotionChange", ErrorString);
				return ;
			}

			wStr="OK";
			lblComment.Text = wStr;
			//---------------------------
			// Get parameters of Driver
			//---------------------------
			bRet = GetMoveParam();
			if( bRet == false )return;
		}
	}
}
